import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class Test {
public static void main(String[] args) {

	 System.out.println(
     "Copyright 2004, R.G.Baldwin");
try {
Statement stmt;
ResultSet rs;

//Register the JDBC driver for MySQL.
Class.forName("com.mysql.jdbc.Driver");

String url =
    "jdbc:mysql://localhost:3306/studienarbeit";

Connection con =
    DriverManager.getConnection(
       url,"admin", "cisco");

//Display URL and connection information
System.out.println("URL: " + url);
System.out.println("Connection: " + con);

//Get a Statement object
stmt = con.createStatement();

try{
    stmt.executeUpdate("DROP TABLE myTable");
  }catch(Exception e){
    System.out.print(e);
    System.out.println(
              "No existing table to delete");
  }//end catch
  
  stmt.executeUpdate(
          "CREATE TABLE myTable(test_id int," +
                "test_val char(15) not null)");
  
  
  stmt.executeUpdate(
          "INSERT INTO myTable(test_id, " +
              "test_val) VALUES(1,'One')");
  
  
  stmt.executeUpdate(
          "INSERT INTO myTable(test_id, " +
              "test_val) VALUES(2,'Two')");
stmt.executeUpdate(
          "INSERT INTO myTable(test_id, " +
            "test_val) VALUES(3,'Three')");
stmt.executeUpdate(
          "INSERT INTO myTable(test_id, " +
             "test_val) VALUES(4,'Four')");
stmt.executeUpdate(
          "INSERT INTO myTable(test_id, " +
             "test_val) VALUES(5,'Five')");

stmt = con.createStatement(
        ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_READ_ONLY);

rs = stmt.executeQuery("SELECT * " +
"from myTable ORDER BY test_id");

System.out.println("Display all results:");
while(rs.next()){
  int theInt= rs.getInt("test_id");
  String str = rs.getString("test_val");
  System.out.println("\ttest_id= " + theInt
                       + "\tstr = " + str);
}//end while loop

System.out.println(
"Display row number 2:");
if( rs.absolute(2) ){
int theInt= rs.getInt("test_id");
String str = rs.getString("test_val");
System.out.println("\ttest_id= " + theInt
     + "\tstr = " + str);
}//end if




con.close();
}catch( Exception e ) {
e.printStackTrace();
}//end catch

  
}
}
